﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pay.Entity;
using pay.BLL;
using System.Text;
public partial class shopping2 : System.Web.UI.Page
{
    public string str_sb = "";
    public string uname = "";
    public string tel = "";
    public string buylist = "";
    public string LinkMan = "";
    public string Msg = "";

    protected void Page_Load(object sender, EventArgs e)
    {



        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request["uname"].ToString()))
            {
                Response.Write("<script>alert('用户姓名不能为空!'); this.history.back(-1);</script>");
                return;
            }
            if (string.IsNullOrEmpty(Request["tel"].ToString()))
            {
                Response.Write("<script>alert('联系电话不能为空！!'); this.history.back(-1);</script>");
                return;
            
            }
            uname = Request["uname"].ToString();
            tel = Request["tel"].ToString();
            LinkMan = getLinkMan();
            buylist = BuyList().ToString();
            Session["uname"] = uname;
            Session["tel"] = tel;
            Session["Linkman"] = LinkMan;
            
        }


    }
    public  double tmpallAmount = 0;
    public StringBuilder BuyList()
    {
        StringBuilder sb = new StringBuilder();
        
        if (Session["EmoneyShopCard"] != null)
        {
            List<ShopCard> list = (List<ShopCard>)Session["EmoneyShopCard"];
            ProductBLL productbll = new ProductBLL();

            sb.AppendLine(" <table border=\"0\"  cellpadding=\"0\" cellspacing=\"0\" width=\"960\" style=\"border:1px solid #e4e4e4;height:auto;border-top:none;line-height:36px;\">");
            sb.AppendLine(" <tr align=\"center\" style=\"background-image: url('images/product-bg.png');background-repeat: repeat-x;height:35px;\"><th>产品名称</th><th>单价</th><th>数量</th><th>小计</th></tr>");
            foreach (var c in list)
            {
                Product product = productbll.GetElementById(c.ProductId);
                c.ProductName = product.Productname;
                c.Price = product.Nowprice.Value;
                tmpallAmount += c.Amount;
                sb.AppendLine("<tr  align=\"center\" id=\"tr_list\" >");

                sb.AppendLine("<td>" + c.ProductName + "</td>");
                sb.AppendLine("<td id=\"price\">" + c.Price + "</td>");
                sb.AppendLine("<td id=\"cost\">"+c.Count+"</td>");
                sb.AppendLine("<td id=\"amount\">" + c.Amount + "</td>");
              
            }

        }
    
        sb.AppendLine(" </table>"); 
        return sb;
    }


    //public string getname()
    //{
    //    if (Request["uname"] != null)
    //    {   
    //        uname = Request["uname"].ToString().Replace("<","&lt;").Replace(">","&gt;");
            
    //    }
    //    return uname;

    //}
    //public string getTel()
    //{
    //    if (Request["tel"] != null)
    //    {
    //        tel = Request["tel"].ToString();

    //    }

    //    return tel;
    //}

    public string  getLinkMan()
    {
        if (Request["LinkMan"] != null)
        {
            LinkMan = Request["LinkMan"].ToString();
        }

        return LinkMan;
    }
}